package com.lsq.baseadmin.modules.manage.controller;


import com.github.pagehelper.PageInfo;
import com.lsq.baseadmin.modules.manage.entity.Position;
import com.lsq.baseadmin.modules.manage.service.PositionService;
import io.swagger.annotations.ApiOperation;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author lsq
 * @since 2020-10-27
 */
@RestController
@RequestMapping("/position")
public class PositionController {

    private PositionService positionService;

    public PositionController(PositionService positionService) {
        this.positionService = positionService;
    }

    @ApiOperation("职位列表")
    @GetMapping("/list")
    public ResponseEntity list(Position position, int pageNum, int pageSize) {
        PageInfo pg = positionService.pg(position, pageNum, pageSize);
        return ResponseEntity.ok(pg);
    }

    @ApiOperation("职位添加")
    @PostMapping("/add")
    public ResponseEntity add(@RequestBody Position position) {
        positionService.save(position);
        return new ResponseEntity(HttpStatus.OK);
    }

    @ApiOperation("职位修改")
    @PostMapping("/update")
    public ResponseEntity update(@RequestBody Position position) {
        positionService.updateById(position);
        return new ResponseEntity(HttpStatus.OK);
    }

    @ApiOperation("职位删除")
    @PostMapping("/delete")
    public ResponseEntity delete(int id) {
        positionService.removeById(id);
        return new ResponseEntity(HttpStatus.OK);
    }
}
